package com.osmap.openstreetmap.ui.fragment;

import java.util.ArrayList;
import java.util.List;

import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Spinner;

import com.osmap.openstreetmap.R;
import com.osmap.openstreetmap.adapter.FootmarkCleanAdapter;
import com.osmap.openstreetmap.bean.FileBeans;
import com.osmap.openstreetmap.bean.FootmarkCleanBeans;
import com.osmap.openstreetmap.json.FootmarkCleanJson;
import com.osmap.openstreetmap.ui.BaseFragment;
import com.osmap.openstreetmap.ui.activity.FootmarkCleanMapActivity;
import com.osmap.openstreetmap.utils.FileUtils;

public class FootmarkClean extends BaseFragment implements OnClickListener {

	private Button mSelector, mNextBtn;
	private ListView mList;
	private FootmarkCleanAdapter mAdapter;
	private FootmarkCleanJson mCleanJson;
	private List<FootmarkCleanBeans> mFootList;
	public List<FileBeans> mFileList;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.fragment_footmark_clean,
				container, false);
		initView(view);
		return view;
	}

	private void initView(View view) {
		mList = (ListView) view.findViewById(R.id.lv_footmark_clean);
		mCleanJson = new FootmarkCleanJson();
		mFootList = new ArrayList<FootmarkCleanBeans>();
		FootmarkCleanBeans clean = null;
		Thread thread = new Thread(new Runnable() {

			@Override
			public void run() {
				mFileList = FileUtils.getInstances(getActivity()).searchFile(
						"",
						Environment.getExternalStorageDirectory() + "/osmap/");
				if (mFileList.size() > 0) {
					Log.e("", mFileList.size() + "");
					mAdapter = new FootmarkCleanAdapter(mFileList,
							getActivity());
					mList.setAdapter(mAdapter);
				}

			}
		});

		for (int i = 0; i < 30; i++) {
			clean = new FootmarkCleanBeans();

			mFootList.add(clean);
		}
		mCleanJson.list = mFootList;

		mNextBtn = (Button) view.findViewById(R.id.btn_next);
		mNextBtn.setOnClickListener(this);
		Spinner s1 = (Spinner) view.findViewById(R.id.btn_selector);
		ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
				getActivity(), R.array.spinner,
				android.R.layout.simple_spinner_item);
		adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		s1.setAdapter(adapter);
		thread.start();
	}

	@Override
	public void onClick(View v) {
		Intent intent = new Intent(getActivity(),
				FootmarkCleanMapActivity.class);
		getActivity().startActivity(intent);
	}

}
